<%@page import="org.apache.commons.lang3.text.WordUtils"%>
<%@page import="org.apache.commons.lang3.StringUtils"%>
<%@page import="projectchumashgeniusproject.Chapter"%>
<%@page import="projectchumashgeniusproject.Word"%>
<%@page import="projectchumashgeniusproject.Phrase"%>
<%@page import="projectchumashgeniusproject.Verse"%>
<%@page import="projectchumashgeniusproject.Book"%>
<%@page import="projectchumashgeniusproject.ProjectChumashGeniusProject.BookName"%>
<%@page import="org.apache.commons.lang3.EnumUtils"%>
<%@page import="org.apache.commons.validator.routines.IntegerValidator"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    //Make Sure BookName is valid
    BookName bookName = EnumUtils.getEnum(BookName.class, request.getParameter("BookName"));
    if (bookName == null) {
        bookName = BookName.GENESIS;
    }
    Book book = new Book(bookName);
    //Make sure chapter number is valid
    IntegerValidator intValidator = new IntegerValidator();
    Integer chapterNumber = intValidator.validate(request.getParameter("Chapt"));
    if (chapterNumber == null || !intValidator.isInRange(chapterNumber, 1, book.getChapters().size())) {
        chapterNumber = 1;
    }   
%>
<p class="TableHeaderText"><%= WordUtils.capitalizeFully(bookName.toString()) %> Chapter <%= chapterNumber.toString() %></p>
<table class="ChumashTextTable" >
    <tbody class="ChumashTableBody" >
        <tr>
            <td>
                <% 
                    //Need to get the Chapter--- book.getChapter(chapterNumber)
                    Chapter chapter = book.getChapters().get(chapterNumber);
                    for (Verse verse : chapter.getVerses()) {
                        for (Phrase phrase : verse.getPhrases()) {
                %>
                <table class="Phrase">
                    <tr>
                        <td class="Hebrew">
                            <%
                                for (Word word : phrase.getWords()) {%>
                            <span class="Shoresh PowerTip" data-shoresh="<%= word.getRoot()%>"><%= word.getWord()%></span>
                            <% }%>
                        </td>
                    </tr>
                    <tr>
                        <td><span class="English"><%= phrase.getEnglishTranslation()%></span></td>
                    </tr>
                </table>     
                <%   }
                        } %>                   
            </td>
        </tr>
    </tbody>
</table>

